# Makefile for LCD Simulator Project
CC      = gcc
CFLAGS  = -Wall -Wextra -g -std=c11
LDFLAGS = -pthread 
TARGET  = lcd_sim
SRCDIR  = .
OBJDIR  = OBJ

SOURCES = $(wildcard $(SRCDIR)/*.c)
OBJECTS = $(patsubst $(SRCDIR)/%.c,$(OBJDIR)/%.o,$(SOURCES))
HEADERS = $(wildcard $(SRCDIR)/*.h)

.PHONY: all clean

all: $(OBJDIR) $(TARGET)

$(TARGET): $(OBJECTS)
	$(CC) $(CFLAGS) $^ -o $(OBJDIR)/$@ $(LDFLAGS) 

$(OBJDIR)/%.o: $(SRCDIR)/%.c $(HEADERS)
	$(CC) $(CFLAGS) -c $< -o $@

$(OBJDIR):
	mkdir -p $(OBJDIR)

clean:
	rm -rf $(OBJDIR) $(TARGET)

# 测试运行（需要编译后执行）
test: $(TARGET)
	@echo "Running simulation..."
	@./$(OBJDIR)/$(TARGET)

# 调试支持
debug: CFLAGS += -DDEBUG -O0
debug: clean all

# 生产构建（优化版本）
release: CFLAGS += -O3 -DNDEBUG
release: clean all